package org.lab.listener;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

public class InforListener extends HttpServlet {

	private static final long serialVersionUID = 1L;

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
	}
	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		Map<String, Map<String,String[]>> map = new HashMap<String, Map<String,String[]>>();
		Logger log = Logger.getLogger(InforListener.class);
		log.info("开始加载map信息");
		//public content
		Map<String,String[]> temp = new HashMap<String, String[]>();
		Map<String,String[]> mPublic = new HashMap<String, String[]>();
		mPublic.put("Participant", new String[]{"参与者","获取参与者Id用以派生度量中的统计计算"});
		mPublic.put("Participant_Type", new String[]{"参与者类型","判断参与者权限"});
		mPublic.put("ActivityType", new String[]{"活动类型","判断该活动是否开始或结束节点"});
		mPublic.put("Timelimit", new String[]{"时间阈值","最常运行时间"});
		mPublic.put("OvertimeType", new String[]{"超时处理","超时处理"});
		//activity content
		Map<String,String[]> mActivity = new HashMap<String, String[]>();
		temp = mPublic;
		publicToOtherMap(temp, mActivity);
		mActivity.put("activity_ins_id",new String[]{"活动实例","该活动实例ID将用于在多流程度量中的计数"});
		mActivity.put("start_time",new String[]{"活动开始时间","活动实例开始运行时间用于派生度量中公式计算"});
		mActivity.put("end_time",new String[]{"活动结束时间","活动实例结束运行时间用于派生度量中公式计算"});
		mActivity.put("JionType",new String[]{"前转移类型","活动前信牌箱到活动的转移类型"});
		mActivity.put("SplitType",new String[]{"后转移类型","活动的转移类型"});
		mActivity.put("ActivityTime",new String[]{"活动运行时间","单实例中单个活动运行时间统计"});
		//subprocess content
		Map<String,String[]> msub = new HashMap<String, String[]>();
		temp = mPublic;
		publicToOtherMap(temp, msub);
		msub.put("SubProcessTime",new String[]{"子流程运行时间","单实例子流程运行运行时间用于派生度量"});
		msub.put("averagetime",new String[]{"子流程活动平均运行时间","单实例子流程运行中活动平均运行时间用于派生度量"});
		//process content
		Map<String,String[]> mpro = new HashMap<String, String[]>();
		temp = mPublic;
		publicToOtherMap(temp, mpro);
		mpro.put("process_ins_id",new String[]{"流程实例","该流程实例ID将用于在多流程度量中的计数"});
		mpro.put("averageeffort",new String[]{"参与者平均工作量","单实例流程中参与者平均工作用时"});
		mpro.put("ProcessTime",new String[]{"流程运行时间","单实例流程运行时间用于派生度量"});
		mpro.put("averageactivitytime",new String[]{"流程中活动平均运行时间","单实例流程运行中活动平均运行时间用于派生度量"});
		//将各种类型放入map中
		map.put("activity", mActivity);
		map.put("subprocess", msub);
		map.put("process", mpro);
		ServletContext app=getServletContext();
		app.setAttribute("metricname", map);
		log.info("完成加载map信息");
	}
	/**
	 * 将公共内容放入其他map中
	 * @param mapPublic
	 * @param otherMap
	 * @author 李晓娜
	 * Apr 8, 2009
	 */
	private void publicToOtherMap(Map<String,String[]> mapPublic, Map<String,String[]> otherMap){
		Iterator<String> it = mapPublic.keySet().iterator();
		while(it.hasNext()){
			String str = it.next();
			otherMap.put(str , mapPublic.get(str));
		}
	}
}
